 <template>
  <div>
    <div class="home_box1">
      <div class="home_box1_left">
        <div class="top">代办提醒</div>
        <ul>
          <li>
            <span>11</span>
            <el-button size="mini" type="primary">详情</el-button>
          </li>
        </ul>
      </div>
      <div class="home_box1_right">
        <div class="top">销售计划</div>
        <template>
          <el-table :data="tableData" style="width: 100%" height="280px" stripe>
            <el-table-column type="index" label="序号" align="center"></el-table-column>
            <el-table-column prop="createon" label="创建时间" align="center"></el-table-column>
            <el-table-column prop="year" label="年份" align="center"></el-table-column>
            <el-table-column prop="month" label="月份" align="center"></el-table-column>
            <el-table-column prop="preparename" label="制单人" align="center"></el-table-column>
          </el-table>
        </template>
      </div>
    </div>
    <div class="home_box2">
      <div id="home_box55_left">
        <div class="top">订单分析</div>
        <div id="home_box2_left"></div>
      </div>
      <div class="home_box2_right">
        <div class="home_box2_right_left">
          <div class="top">客户管理</div>
          <table width="100%">
            <!-- <tr>
              <td>
                <em>99</em>
                <span>合作客户</span>
              </td>
              <td>
                <em>0</em>
                <span>欠款客户</span>
              </td>
              <td>
                <i>0</i>
                <span>到期未结清</span>
              </td>
            </tr>-->
          </table>
          <template>
            <el-table :data="tableData2" style="width: 100%" height="240px" stripe>
              <el-table-column prop="componyno" label="编号" align="center"></el-table-column>
              <el-table-column prop="componyname" label="客户名称" align="center"></el-table-column>
              <el-table-column prop="totalexpriedebt" label="欠款总额(元)" align="center"></el-table-column>
            </el-table>
          </template>
        </div>
        <div class="home_box2_right_right">
          <div class="top">售后管理</div>
          <table width="100%">
            <!-- <tr>
              <td>
                <em>99</em>
                <span>合作客户</span>
              </td>
              <td>
                <em>0</em>
                <span>欠款客户</span>
              </td>
              <td>
                <i>0</i>
                <span>到期未结清</span>
              </td>
            </tr>-->
          </table>
          <template>
            <el-table :data="tableData3" style="width: 100%" height="240px" stripe>
              <el-table-column prop="createon" label="提交时间" align="center"></el-table-column>
              <el-table-column prop="componyname" label="客户名称" align="center"></el-table-column>
              <el-table-column prop="type" label="产品类型" align="center"></el-table-column>
              <el-table-column prop="troublenum" label="问题数量" align="center"></el-table-column>
            </el-table>
          </template>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      tableData: [],
      tableData2: [],
      tableData3: []
    };
  },
  mounted() {
    this.getval();
    setTimeout(() => {
      this.drawLine();
    }, 500);
    this.getlist();
    this.getlista();
    this.getlistb();
  },

  methods: {
    getlist() {
      let arr = {
        pn: 0,
        PerPageSize: 10000,
        key: "",
        start: "",
        end: ""
      };
      let arr1 = JSON.stringify(arr);
      axios(
        "apis/SalesManagement.asmx/OrderPlanlst?index=1&jsondata=" + arr1
      ).then(({ data }) => {
        let data1 = this.$x2js.xml2js(data);
        let data3 = JSON.parse(data1.string.__text);
        console.log(data3);
        this.total = data3.total;
        var val = [];
        data3.lstall.forEach(item => {
          val.push(item);
        });
        this.tableData = val;
        for (var i = 0; i < this.tableData.length; i++) {
          var dd = new Date(parseInt(this.tableData[i].createon.substr(6, 13)));
          var y = dd.getFullYear();
          var m = dd.getMonth() + 1;
          m = m < 10 ? "0" + m : m;
          var d = dd.getDate();
          d = d < 10 ? "0" + d : d;
          this.tableData[i].createon = y + "-" + m + "-" + d + " ";
        }
      });
    },
    getlista() {
      let arr = {
        pn: 0,
        PerPageSize: 10000,
        key: "",
        start: "",
        end: ""
      };
      let arr1 = JSON.stringify(arr);
      axios(
        "apis/SalesManagement.asmx/Customermanlst?index=1&jsondata=" + arr1
      ).then(({ data }) => {
        let data1 = this.$x2js.xml2js(data);
        let data3 = JSON.parse(data1.string.__text);
        console.log(data3);
        var val = [];
        data3.lstall.forEach(element => {
          val.push(element);
        });
        this.tableData2 = val;
      });
    },
    getlistb() {
      let arr = {
        pn: 0,
        PerPageSize: 10000,
        key: "",
        start: "",
        end: ""
      };
      let arr1 = JSON.stringify(arr);
      axios(
        "apis/SalesManagement.asmx/AfterSaleManlst?index=1&jsondata=" + arr1
      ).then(({ data }) => {
        let data1 = this.$x2js.xml2js(data);
        let data3 = JSON.parse(data1.string.__text);
        console.log(data3);
        this.total = data3.total;
        var listval = [];
        data3.lstall.forEach(item => {
          listval.push(item);
        });
        this.tableData3 = listval;
        for (var i = 0; i < this.tableData3.length; i++) {
          var dd = new Date(
            parseInt(this.tableData3[i].createon.substr(6, 13))
          );
          var y = dd.getFullYear();
          var m = dd.getMonth() + 1;
          m = m < 10 ? "0" + m : m;
          var d = dd.getDate();
          d = d < 10 ? "0" + d : d;
          this.tableData3[i].createon = y + "-" + m + "-" + d + " ";
        }
      });
    },
    // 饼状图
    drawLine() {
      // 基于准备好的dom，初始化echarts实例
      let myChart = this.$echarts.init(
        document.getElementById("home_box2_left")
      );
      // 绘制图表
      var xData = (function() {
        var data = [];
        for (var i = 1; i < 13; i++) {
          data.push(i + "月");
        }
        return data;
      })();

      myChart.setOption({
        backgroundColor: "#fff",
        title: {
          text: "",
          subtext: "",
          x: "1%",

          textStyle: {
            color: "#fff",
            fontSize: "22"
          },
          subtextStyle: {
            color: "#909399",
            fontSize: "14",
            fontWeight: "bold"
          }
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
            textStyle: {
              color: "#fff"
            }
          }
        },
        grid: {
          borderWidth: 0,
          top: 80,
          bottom: 30,
          textStyle: {
            color: "#fff"
          }
        },
        legend: {
          x: "60%",
          top: "8%",
          textStyle: {
            color: "#90979c"
          },
          data: ["销售计划", "实际销售计划"]
        },

        calculable: true,
        xAxis: [
          {
            type: "category",
            axisLine: {
              lineStyle: {
                color: "#90979c"
              }
            },
            splitLine: {
              show: false
            },
            axisTick: {
              show: false
            },
            splitArea: {
              show: false
            },
            axisLabel: {
              interval: 0
            },
            data: xData
          }
        ],
        yAxis: [
          {
            type: "value",

            splitLine: {
              show: false
            },
            axisLine: {
              lineStyle: {
                color: "#90979c"
              }
            },
            axisTick: {
              show: false
            },
            axisLabel: {
              show: false
            },
            splitArea: {
              show: false
            }
          }
        ],

        series: [
          {
            name: "销售计划",
            type: "bar",
            stack: "总量",
            barMaxWidth: 35,
            barGap: "10%",
            itemStyle: {
              normal: {
                color: "#409EFF"
              }
            },
            data: [
              709,
              1917,
              2455,
              2610,
              1719,
              1433,
              1544,
              3285,
              5208,
              3372,
              2484,
              4078
            ]
          },

          {
            name: "实际销售计划",
            type: "bar",
            stack: "总量",
            itemStyle: {
              normal: {
                color: "#ebb563",
                barBorderRadius: 0
              }
            },
            data: [
              327,
              1776,
              507,
              1200,
              800,
              482,
              204,
              1390,
              1001,
              951,
              381,
              220
            ]
          }
        ]
      });
    },
    //数据
    getval() {
      axios("apis/SalesManagement.asmx/SaleShouYe").then(({ data }) => {
        let data1 = this.$x2js.xml2js(data);
        let data3 = JSON.parse(data1.string.__text);
        console.log(data3);
      });
    }
  }
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/base.scss";
.top {
  height: 50px;
  line-height: 50px;
  padding-left: 10px;
  padding-right: 10px;
  border-bottom: 1px solid #f5f5f5;
  color: #505050;
  //margin-bottom: 15px;
}
.home_box1 {
  width: 98%;
  padding: 0 1%;
  height: 340px;
  display: flex;
  justify-content: space-around;
  .home_box1_left {
    width: 39%;
    background: $white;
    ul li {
      width: 100%;
      height: 48px;
      line-height: 48px;
      border-bottom: 1px solid #ebeef5;
      span {
        display: inline-block;
        width: 80%;
        padding-left: 1%;
      }
    }
    // position: relative;
    // p {
    //   font-weight: bold;
    //   color: #909399;
    //   font-size: 14px;
    //   position: absolute;
    //   top: 10px;
    //   left: 1%;
    //   z-index: 999;
    // }
  }
  .home_box1_right {
    width: 59%;
    background: $white;
    p {
      font-weight: bold;
      color: #909399;
      font-size: 14px;
      padding: 10px 0 0 1%;
    }
  }
}
.home_box2 {
  height: 300px;
  width: 98%;
  padding: 0 1%;
  display: flex;
  margin-top: 10px;
  justify-content: space-around;
  #home_box55_left {
    width: 39%;
    background: white;
    #home_box2_left {
      width: 100%;
      height: 240px;
      //background: blue;
    }
  }

  .home_box2_right {
    width: 59%;
    display: flex;

    .home_box2_right_left {
      width: 49%;
      background: $white;

      p {
        font-weight: bold;
        color: #909399;
        font-size: 14px;
        padding: 10px 0 0 2%;
      }
      table {
        margin-top: 10px;
        color: #909399;
        td {
          border: solid 1px rgb(224, 224, 224);
          border-left: none;
          border-right: none;
          border-top: none;
          padding: 10px 0;
          width: 33%;
          font-size: 14px;
          text-align: center;
          span {
            display: block;
            width: 100%;
            margin-top: 10px;
          }
          i {
            font-style: normal;
            color: $red;
          }
        }
      }
    }
    .home_box2_right_right {
      width: 49%;
      margin-left: 2%;
      background: $white;

      p {
        font-weight: bold;
        color: #909399;
        font-size: 14px;
        padding: 10px 0 0 2%;
      }
      table {
        color: #909399;
        margin-top: 10px;
        td {
          border: solid 1px rgb(224, 224, 224);
          border-left: none;
          border-right: none;
          border-top: none;
          padding: 10px 0;
          width: 33%;
          font-size: 14px;
          text-align: center;
          span {
            display: block;
            width: 100%;
            margin-top: 10px;
          }
          i {
            font-style: normal;
            color: $red;
          }
        }
      }
    }
  }
}
</style>